#ifndef     __STEAM_TASK_H
#define     __STEAM_TASK_H

#include "../rtos/thread.h"
#include "../rtos/message_queue.h"

namespace heat_task {

class SteamTask : public rtos::Thread<SteamTask, 1024, osPriorityHigh1> {

public: 
    enum class Mode : uint8_t {
        BEGIN,
        OPEN, 
        CLOSE,
    };

    struct ModeValue {
        Mode mode;
        uint8_t sec;
    };

    void init_start();

    void run();

    void begin() {
        m_mq.post(ModeValue { Mode::BEGIN, 0 });
    }

    void close() {
        m_mq.post(ModeValue { Mode::CLOSE, 0 });
    }

    void open(uint8_t sec) {
        m_mq.post(ModeValue { Mode::OPEN, sec });
    }

private:
    void do_close();
    void do_begin();
    void do_open();

    bool wait(uint32_t timeout = osWaitForever) {
        return osOK == m_mq.poll(m_mv, timeout);
    }

    ModeValue m_mv = { Mode::CLOSE, 0 };
    rtos::lazy::MessageQueue<ModeValue, 2> m_mq;
};

extern SteamTask steamTask;

}

#endif
